import global_ from "../../global.config";
import wxsdk from "@/utils/wxsdk";
import request from "@/utils/request";
import Cookies from "js-cookie";
export const ACT_CODE = "wx20190308";
export const BASE_TEXT = "本活动由原圈网络提供技术支持";
export const SHARE_TITLE = "520告白日｜怦然心动，你的“美”一刻”";
export const SHARE_DESC = "吉宝置业美图征集计划，全城动员！";
export const SHARE_LINK = location.protocol + '//' + location.host + '/act/tjkeppel/main';
export const SHARE_NOJOIN_LINK = location.protocol + '//' + location.host + '/act/tjkeppel/index';
export const SHARE_IMG_URL = "http://rs.static.quanc.com.cn/activies/tjkeppel/share.png";
export const projectId = 50;//生产
// export const projectId = 45;//测试
export const activityId = 13;
export function checkaward(list, id) {
  let flag = false;
  list.forEach(function (v, i) {
    if (v.prizecode == id) {
      flag = true;
    }
  })
  return flag;
}
export function initShare(obj) {
  global_.SHARE_TITLE = obj.title || SHARE_TITLE;
  global_.SHARE_DESC = obj.desc || SHARE_DESC;
  global_.SHARE_LINK = obj.link || SHARE_LINK||SHARE_NOJOIN_LINK;
  global_.SHARE_IMG_URL = obj.url || SHARE_IMG_URL;
  wxsdk.init();
}
export function getUserInfo() {
  return new Promise(function (resolve, reject) {
    let userinfoFromCooke = Cookies.get("userinfo");
    if (userinfoFromCooke) {
      resolve(JSON.parse(userinfoFromCooke));
    } else {
      request
        .get(global_.API_URL, {
          action: "getUserinfo",
          requestParam: {}
        })
        .then(function (data) {
          let inFifteenMinutes = new Date(
            new Date().getTime() + 5 * 60 * 1000
          );
          Cookies.set("userinfo", JSON.stringify(data.obj), {
            expires: inFifteenMinutes
          });
          resolve(data.obj);
        });
    }
  });
}

/**
 * 
 * 1. 活动页面上分享的时候，如果分享人是注册的销售或者中介，就在分享链接上加个销售或者中介openid（参数是：registeroid），一直传递下去，直到下一个分享的人也是销售或中介，就替换一下registeroid的值。
 * 2. 提交手机号码等信息的时候，把registeroid也提交上来，调接口：/hb/HbUserAction/addUserInfoWithPhoneAndBindRegister， "requestParam":{"registeroid":"源头的销售/中介的openid，没有就不传","obj":{"openid":"", "mobile":"13213123", "name":"没有就不传"}}}， 这个接口作用是把粉丝的信息同步过来，并绑定到销售或中介的粉丝列表里。
 * 3. 判断是否是注册的销售或中介，用原来的getUserinfo接口返回的salerOrAgent字段， true/false。
 * @param {*} ouid 
 * @param {*} openid 
 * @param {*} mobile 
 * @param {*} name 
 */
export function addUserInfoWithPhoneAndBindRegister(ouid, openid, mobile,name) {
  return new Promise(function (resolve, reject) {
    // "registeroid": "源头的销售/中介的openid，没有就不传", "obj": { "openid": "", "mobile": "13213123", "name": "没有就不传" }
    let requestParam = {};
    if (ouid) {
      requestParam.registeroid = ouid;
    }
    requestParam.obj = {
      openid: openid,
      mobile: mobile
    }
    if (name) {
      requestParam.obj.name = name;
    }
    request
      .get(global_.API_URL, {
        action: "/hb/HbUserAction/addUserInfoWithPhoneAndBindRegister",
        requestParam: requestParam
      })
      .then(function (data) {
        // alert("addUserInfoWithPhoneAndBindRegister")
        // alert(JSON.stringify(data));
        resolve(data);
      });
  });
}